package org.luo.news.domain.category;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;


import org.luo.common.common.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
@Tag(name = "分类管理", description = "分类管理")
public class CategoryController {
    @Autowired
    CategoryService categoryService;

    @PostMapping("/add")
    @Operation(summary = "添加分类", description = "添加分类")
    public Result add(@RequestBody Category category){

        return categoryService.add(category);
    }

    @GetMapping("/list")
    @Operation(summary = "分类列表", description = "分类列表")
    public  Result<List<Category>> list(){
        return categoryService.getList();
    }

    @GetMapping("/detail")
    @Operation(summary = "分类详情", description = "分类详情")
    public  Result<Category> detail(@RequestParam("id") Integer id){
        return categoryService.detail(id);
    }

    @PutMapping("/update")
    @Operation(summary = "更新分类", description = "更新分类")
    public Result update(@RequestBody  Category category){
        return categoryService.update(category);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除分类", description = "删除分类")
    public  Result delete(Integer id){

        return categoryService.delete(id);
    }
}
